#ifndef SERIALPORTCOMMUNICATION_H
#define SERIALPORTCOMMUNICATION_H

#include <QWidget>
#include <QtSerialPort/QSerialPort>
#include "serialportdialog.h"
//#include "serialportmasterthread.h"

namespace Ui {
class SerialPortCommunication;
}

class SerialPortMasterThread;

class SerialPortCommunication : public QWidget
{
    Q_OBJECT

public:
    explicit SerialPortCommunication(QWidget *parent = 0);
    ~SerialPortCommunication();

    void setSerialPortInstance(QSerialPort *portInstance);

    void getSerialPortSettings(SerialPortDialog::SerialPortSettings settings);

private:
    void serialportSettings();
    void setControlsEnabled(bool enable);

signals:
    void signalSerialPortConnected();

private slots:
    void slotTransaction();
    void slotStopTransaction();
    void slotShowResponse(const QString &s);
    void slotProcessError(const QString &s);
    void slotProcessTimeout(const QString &s);

    void slotSerialPortConnected();

    void slotAutoTransactionToggled(bool checked);

private:
    Ui::SerialPortCommunication *ui;

    QSerialPort *m_portInstance;

    int m_transactionCount;

    SerialPortDialog::SerialPortSettings m_settings;

    QString m_portName;
    qint32 m_baudRate;
    QSerialPort::DataBits m_dateBits;
    QSerialPort::Parity m_parity;
    QSerialPort::StopBits m_stopBits;
    QSerialPort::FlowControl m_flowControl;

    QString m_request;
    int m_waitResponse;

    SerialPortMasterThread *m_masterThread;
};

#endif // SERIALPORTCOMMUNICATION_H
